/*Copyright (c) 2012 Nicolás Zalaquett

Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the
Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice
shall be included in all copies or substantial portions of
the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/
package extrae;

import javafx.scene.CustomNode;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.image.Image;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.geometry.HPos;
import javafx.scene.text.TextAlignment;
import javafx.geometry.VPos;
import javafx.scene.image.ImageView;
import javafx.scene.layout.LayoutInfo;
import extrae.selectorSensores.sensorAN;
import javafx.scene.effect.DropShadow;
import javafx.scene.effect.InnerShadow;
import javafx.scene.layout.VBox;
import javafx.geometry.Insets;
import javafx.scene.control.Button;
import javafx.scene.layout.Priority;


/**
 * @author lojkoro
 */

/*canalAnalogo: Nodo visual para representar (y modificar) el estado
 *de cada canal análogo (en la instancia de parametrosAnalogo de Main)*/
public class canalAnalogo extends CustomNode {
    public var botonAux:Button=Button{};
    public var sensor:sensorAN;
    public var i:Integer=0;
    public var titulo: javafx.scene.control.Label = javafx.scene.control.Label {
                visible: true
                vpos:VPos.TOP
                hpos:HPos.CENTER
                text: "AN{i}"
            }
    public var info: javafx.scene.control.Label = javafx.scene.control.Label {
                text: bind "{sensor.nombre}\nResolución:\n{sensor.resolucion} {sensor.unidades}"
                textFill: Color.RED
                font: Font { size: 11 }
                hpos: HPos.CENTER
                textAlignment: TextAlignment.CENTER
                vpos: VPos.CENTER
            }
    public var checkboxAN: javafx.scene.control.CheckBox = javafx.scene.control.CheckBox {
                vpos:VPos.CENTER
                hpos:HPos.CENTER
                text: "Activo"
            }
    public var botonAN: javafx.scene.control.Button = javafx.scene.control.Button {
                visible: true
                vpos:VPos.CENTER
                hpos:HPos.CENTER
                layoutInfo: LayoutInfo{width: 55.0
                                       height: 55.0
                                       hgrow:Priority.NEVER}
                onMouseEntered: function(event) {
                    botonAN.effect = DropShadow{};
                }
                onMouseExited: function(event) {
                    botonAN.effect = null;
                }
                onMousePressed: function(event) {
                    botonAN.effect = InnerShadow{};
                }
                onMouseReleased: function(event) {
                    botonAN.effect = DropShadow{};
                }
                graphic: ImageView{image:Image{url: "{__DIR__}recursos/Analogo.png"
                                               width: 55.0
                                               height:55.0
                                               preserveRatio: true}
                                   layoutInfo: LayoutInfo{hgrow:Priority.NEVER
                                                          hpos:HPos.CENTER}}

                styleClass:"button1"
                action:bind botonAux.action;
              
            }
    public var imageSensorAN: javafx.scene.image.ImageView = javafx.scene.image.ImageView {
                disable: false
                image: bind Image { url: "{__DIR__}recursos/{sensor.imagen}"
                    smooth: true
                    width: 80
                    height: 80
                    preserveRatio: true
                }
            }
    public var ordenVertical:VBox =VBox{
        padding: Insets { top: 12 right: 4 bottom: 12 left: 4}
        spacing: 12
        nodeHPos: HPos.CENTER
	content: [titulo,botonAN,checkboxAN,info,imageSensorAN,]
    }

    public override function create(): Node {
        Group {
            content: [ordenVertical]
        }
    }
}
